from common.log.log_client import log
from datetime import datetime


def singleton(cls):
    instance = {}

    def wapper():
        if cls not in instance:
            instance[cls] = cls()
        return instance[cls]
    return wapper



@singleton
class assertMsg:
    def __init__(self):
        self.lastErrorMsg = ""

    def my_assert(self,check,Msg):
        if check:
            pass
        else:
            timestr = datetime.now().strftime("%Y-%m-%d-%H-%S.%f")
            self.lastErrorMsg = timestr + Msg
            log.error(Msg)
            assert check,Msg


mAssert = assertMsg()